<#import "/META-INF/spring.ftl" as spring />
<#import "/META-INF/mspring.ftl" as mspring />
<#include "../inc/header.ftl" />
	<form id="postForm" name="postForm" action="${base}/admin/post/list" method="POST">
		<@spring.bind "post" />
		<table>
			<tr>
				<td class="fieldlabel" style="width:50px;">状态</td>
				<td>
					<@spring.formSingleSelect path="post.status" options=status attributes='onchange="changeStatus();"' />
				</td>
				
				<td class="fieldlabel" style="width:50px;">标题</td>
				<td>
					<@spring.formInput path="post.title" attributes='class="textinput"' />
				</td>
				
				<td class="fieldlabel" style="width:50px;">用户编号</td>
				<td>
					<@spring.formInput path="post.author.id" attributes='class="textinput"' />
				</td>
				
				<td class="fieldlabel" style="width:50px;">用户名</td>
				<td>
					<@spring.formInput path="post.author.name" attributes='class="textinput"' />
				</td>
				
				<td class="fieldlabel" style="width:50px;">用户昵称</td>
				<td>
					<@spring.formInput path="post.author.alias" attributes='class="textinput"' />
				</td>
				<td><input type="submit" class="btn" value=" 查 询 " /></td>
			</tr>
		</table>
		
		<@spring.bind "postPage" />
		<!-- pagination parameter -->
		<@spring.formHiddenInput path="postPage.pageNo" />
		<@spring.formHiddenInput path="postPage.totalPages" />
		<@spring.formHiddenInput path="postPage.totalCount" />
		<!-- sorter parameter -->
		<@spring.formHiddenInput path="postPage.sortEnable" />
		<@spring.formHiddenInput path="postPage.sort.field" />
		<@spring.formHiddenInput path="postPage.sort.order" />
		
		<table class="dtable" cellspacing="0" cellpadding="0">
			<tr>
				<th>
					<input type="checkbox" onclick="mlog.form.checkAll(this, 'id');" />
				</th>
				<th onclick="sortField(this, 'postForm', 'id');" id='id_sort'>编号</th>
				<th onclick="sortField(this, 'postForm', 'title');" id='title_sort'>标题</th>
				<th onclick="sortField(this, 'postForm', 'author.alias');" id='author.alias_sort'>作者</th>
				<th onclick="sortField(this, 'postForm', 'catalog.name');" id='catalog.name_sort'>分类</th>
				<th onclick="sortField(this, 'postForm', 'createTime');" id='createTime_sort'>创建时间</th>
				<th onclick="sortField(this, 'postForm', 'isTop');" id='isTop_sort'>置顶？</th>
				<th>操作</th>
			</tr>
			<#if postPage?exists>
				<#list postPage.result as item>
					<#assign tdClass = "odd">
					<#if item_index%2 == 0>
						<#assign tdClass = "even">
					</#if>
					<tr>
						<td class="${tdClass}"><input type="checkbox" name="id" value="${item.id}" /></td>
						<td class="${tdClass}">${item.id}</td>
						<td class="${tdClass}"><a href="<@postUrl id="${item.id}" username="${item.author.name}" />" title="${item.title}" target="_blank"><@mspring.sub_string content=item.title to=20 suffix="..." /></a></td>
						<td class="${tdClass}">${item.author.alias}</td>
						<td class="${tdClass}"><#if item.catalog?exists>${item.catalog.name}</#if></td>
						<td class="${tdClass}">${item.createTime}</td>
						<td class="${tdClass}">
							<a href="javascript:setTop(${item.id}, 'false')" id="top_true_${item.id}" style="color:red;<#if !item.isTop>display:none;</#if>">是</a>
							<a href="javascript:setTop(${item.id}, 'true')" id="top_false_${item.id}" <#if item.isTop>style="display:none;"</#if>>否</a>
						</td>
						<td class="${tdClass}">
							<a href="${base}/admin/post/edit?id=${item.id}">修改</a>
						</td>
					</tr>
				</#list>
			</#if>
		</table>
		<table style="width:100%;">
			<tr>
				<td>
					<#-- 当筛选条件为回收站 -->
					<#if post?exists && post.status?has_content && post.status == 'trash'>
						<input type="button" class="btn" value=" 彻底删除 " onclick="mlog.form.confirmSubmit('postForm', '${base}/admin/post/delete', '你确认要彻底删除选中文章吗?');" />
						<input type="button" class="btn" value=" 恢复文章 " onclick="mlog.form.confirmSubmit('postForm', '${base}/admin/post/trash2Publish', '你确认要恢复选中文章吗?');" />
						<input type="button" class="btn" value=" 清空回收站 " onclick="mlog.form.confirmSubmit('postForm', '${base}/admin/post/clearTrash', '你确认要清空回收站吗?');" />
					<#elseif post?exists && post.status?has_content && post.status == 'draft'>
						<input type="button" class="btn" value=" 彻底删除 " onclick="mlog.form.confirmSubmit('postForm', '${base}/admin/post/delete', '你确认要彻底删除选中草稿吗?');" />
					<#else>
						<input type="button" class="btn" value=" 移入回收站 " onclick="mlog.form.confirmSubmit('postForm', '${base}/admin/post/trash', '确认要将选中文章移入回收站吗?');" />
					</#if>
				</td>
				<td>
					<@mspring.pagingnavigator page=postPage form_id="postForm" />
				</td>
			</tr>
		</table>
	</form>

	
	<script type="text/javascript">
		function changeStatus(){
			$("#postForm").submit();
		}
		
		//设置文章置顶
		function setTop(id, top){
			$.get('${base}/admin/post/top?id=' + id + '&top=' + top, function(response){
				if(response == 'true'){
					if(top == 'true'){
						$("#top_true_" + id).css('display', 'inline');
						$("#top_false_" + id).css('display', 'none');
					}
					else{
						$("#top_true_" + id).css('display', 'none');
						$("#top_false_" + id).css('display', 'inline');
					}
					mlog.dialog.tip({
						msg:'设置成功'
					});
				}
				else {
					mlog.dialog.tip({
						msg:'设置失败',
						type:'error'
					});
				}
			});
		}
	</script>
<#include "../inc/footer.ftl" />